﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;
using QLTuyenXe.DAL;
using QLTuyenXe.DAO;

namespace QLTuyenXe.BLL
{
    class BCONGTY
    {
        MyConnectUnit myConnU = new MyConnectUnit();

        //Load len combobox
        public DataTable Select(String columns, String condition, String order)
        {
            DataTable tb = new DataTable();
            tb = myConnU.Select("CONG_TY", columns, condition, order);  
            return tb;
        }


        public DataTable Select(String columns, String condition)
        {
            return this.Select(columns, condition, null);
        }

        public DataTable Select(String columns)
        {
            return this.Select(columns, null);
        }

        public DataTable Select()
        {
            return this.Select("*");
        }

        //Thêm 1 chức vụ mới
        public int Insert(CONGTY congTy)
        {
            ColumnData tenCT = new ColumnData("tenCT", 1, congTy.TenCT.ToString());
            ColumnData diaChi = new ColumnData("diaChi", 1, congTy.DiaChi.ToString());
            ColumnData soDT = new ColumnData("soDT", 1, congTy.SoDT.ToString());
            ColumnData fax = new ColumnData("fax", 1, congTy.Fax.ToString());
            //ColumnData giamDoc = new ColumnData("giamDoc", 1, congTy.GiamDoc.ToString());
            ArrayList ob = new ArrayList();
            ob.Add(tenCT);
            ob.Add(diaChi);
            ob.Add(soDT);
            ob.Add(fax);
            //ob.Add(giamDoc);
            return myConnU.Insert("CONG_TY", ob);
        }
        //Them vao 1 danh sach
        public int Insert(ArrayList f)
        {
            int count = 0;
            foreach (CONGTY cv in f)
            {
                count += this.Insert(cv);
            }
            return count;
        }
        //Cap nhat thong tin cho 1 dt
        public int Update(CONGTY congTy, String condition)
        {
            ColumnData tenCT = new ColumnData("tenCT", 1, congTy.TenCT.ToString());
            ColumnData diaChi = new ColumnData("diaChi", 1, congTy.DiaChi.ToString());
            ColumnData soDT = new ColumnData("soDT", 1, congTy.SoDT.ToString());
            ColumnData fax = new ColumnData("fax", 1, congTy.Fax.ToString());
            ColumnData hoTen = new ColumnData("hoten", 1, congTy.Hoten.ToString());
            ArrayList ob = new ArrayList();
            ob.Add(tenCT);
            ob.Add(diaChi);
            ob.Add(soDT);
            ob.Add(fax);
            ob.Add(hoTen);
            return myConnU.Update("CONG_TY", ob, condition);
        }
        //Cap nhat 1 danh sach
        public int Update(ArrayList ks, String condition)
        {
            int count = 0;
            foreach (CONGTY a in ks)
            {
                count += this.Update(a, condition);
            }
            return count;
        }
        //Xoa chuc vu theo dieu kien
        public int Delete(String condition)
        {
            return myConnU.Delete("CONG_TY", condition);
        }
        //Lay ma lon nhat
        public int GetMaxId()
        {
            return myConnU.GetMaxId("CONG_TY", "id");
        }
    }
}
